package DataStructure.GenericLearning.Demo3;

import java.util.ArrayList;

/**
 *  泛型的通配和数组协变
 */
public class Test2 {
    public static void main(String[] args) {

        S2[] ss = new S2[10];
        // JVM会对数组做特殊处理：协变
        F[] fs = ss;

        fs[0] = new S3(); // 报错

        //ArrayList<?> list = new ArrayList<F>();
        //list.add(new F());  // 错误
        //list.add((new Object())); // 错误
        //list.add(new S2()); // 错误

        //ArrayList<F> list2 = new ArrayList<F>();
        //list2.add(new F());  // 错误
        //list2.add((new Object())); // 错误
        //list2.add(new S3()); // 错误

        //ArrayList<? super F> list3 = new ArrayList<F>();
        //list3.add(new F()); // 未报错
        //list3.add((new Object())); // 错误
        //list3.add(new S2()); // 未报错

    }
}

class F{}
class S2 extends F {}
class S3 extends F {}
